package com.jigsaw.repository;

import com.jigsaw.model.MoviesInfoEntity;
import com.jigsaw.model.UserEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;

/**
 * Created by Jigsaw on 2016/4/4.
 */
@Repository
public interface UserRepository extends JpaRepository<UserEntity, Integer> {
    @Query("select us from UserEntity us where us.username=:qusername")
    public UserEntity findByUsername(@Param("qusername") String username);

    @Query("select us.email from UserEntity us where us.email=:qemail")
    public UserEntity findByEmail(@Param("qemail") String email);

    @Modifying // 说明该方法是修改操作
    @Transactional // 说明该方法是事务性操作
    // 定义查询
    // @Param注解用于提取参数
    @Query("update UserEntity us set us.viewTime=:qviewTime, us.lastTime=:qlastTime, us.privateToken=:mtoken where us.email=:qemail")
    public void updateUser(@Param("qviewTime") Integer viewTime,
                           @Param("qlastTime") Timestamp lastTime,
                           @Param("mtoken") String privateToken,
                           @Param("qemail") String email);
}
